package com.sunday.pinxinghui.model.order;

import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewStub;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.sunday.common.base.BaseActivity;
import com.sunday.common.model.ResultDO;
import com.sunday.common.utils.Constants;
import com.sunday.common.utils.SpannalbeStringUtils;
import com.sunday.common.utils.ToastUtils;
import com.sunday.common.widgets.NoScrollListview;
import com.sunday.pinxinghui.MainActivity;
import com.sunday.pinxinghui.R;
import com.sunday.pinxinghui.adapter.OrderProductAdapter;
import com.sunday.pinxinghui.base.BaseApplication;
import com.sunday.pinxinghui.entity.Order;
import com.sunday.pinxinghui.model.WebViewActivity;
import com.sunday.pinxinghui.model.products.ProductDetailActivity;
import com.sunday.pinxinghui.network.ApiClient;

import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static com.sunday.pinxinghui.R.id.tvStatus;

/**
 * Created by 刘涛 on 2017/8/19.
 */

public class OrderDetailActivity extends BaseActivity {

    @Bind(R.id.title_view)
    TextView titleView;
    @Bind(R.id.order_status)
    TextView orderStatus;
    @Bind(R.id.user_name)
    TextView userName;
    @Bind(R.id.user_addr)
    TextView userAddr;
    @Bind(R.id.remark)
    TextView remark;
    @Bind(R.id.list_view)
    NoScrollListview listView;
    @Bind(R.id.express_money)
    TextView expressMoney;
    @Bind(R.id.coupon_money)
    TextView couponMoney;

    @Bind(R.id.total_money)
    TextView totalMoney;
    @Bind(R.id.order_no)
    TextView orderNo;
    @Bind(R.id.order_create_time)
    TextView orderCreateTime;
    @Bind(R.id.order_pay_time)
    TextView orderPayTime;
    @Bind(R.id.order_btn1)
    TextView orderBtn1;
    @Bind(R.id.order_btn2)
    TextView orderBtn2;
    @Bind(R.id.btn_layout)
    RelativeLayout btnLayout;
    @Bind(R.id.order_btn3)
    TextView orderBtn3;
    @Bind(R.id.txt_menu1)
    TextView txtMenu1;
    @Bind(R.id.txt_menu2)
    TextView txtMenu2;
    @Bind(R.id.view_stub)
    ViewStub viewStub;
    @Bind(R.id.txt_reviceve_addr)
    TextView txtReviceveAddr;
    @Bind(R.id.addr_extra_menu1)
    TextView addrExtraMenu1;
    @Bind(R.id.addr_extra_menu2)
    TextView addrExtraMenu2;
    @Bind(R.id.addr_extra_layout)
    LinearLayout addrExtraLayout;
    @Bind(R.id.send_method)
    TextView sendMethod;


    private Order order;
    private long memberId, orderId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_detail);
        ButterKnife.bind(this);
        //order = (Order) getIntent().getSerializableExtra("order");
        orderId = getIntent().getLongExtra("orderId", 0);
        memberId = BaseApplication.getInstance().getMember().getId();
        // memberId = Constants.TEST_MEMBERID;
        titleView.setText("订单详情");
        titleView.setFocusable(true);
        titleView.setFocusableInTouchMode(true);
        titleView.requestFocus();
        getOrderDetail();
    }

    private void getOrderDetail() {
        Call<ResultDO<Order>> call = ApiClient.getApiAdapter().getOrderDetail(orderId, null);
        call.enqueue(new Callback<ResultDO<Order>>() {
            @Override
            public void onResponse(Call<ResultDO<Order>> call, Response<ResultDO<Order>> response) {
                if (isFinish || response.body() == null) {
                    return;
                }
                if (response.body().getCode() == 0) {
                    order = response.body().getResult();
                    initView();
                } else {
                    ToastUtils.showToast(mContext, response.body().getMessage());
                }
            }

            @Override
            public void onFailure(Call<ResultDO<Order>> call, Throwable t) {
                ToastUtils.showToast(mContext, R.string.network_error);
            }
        });
    }

    private void initView() {
        if (order == null) {
            return;
        }
        btnLayout.setVisibility(View.GONE);
        switch (order.getStatus()){
            case 0:
                orderStatus.setText("待付款");
                break;
            case 1:
                orderStatus.setText("待发货");
                break;
            case 2:
                orderStatus.setText("待收货");
                break;
            case 3:
                orderStatus.setText("待评价");
                break;
            case 4:
                orderStatus.setText("交易关闭");
                break;
            case 5:
                orderStatus.setText("退款中");
                break;
            case 6:
                orderStatus.setText("已取消");
                break;
            case 7:
                orderStatus.setText("已退款");

                break;
            case 8:
                orderStatus.setText("退货中");
                break;
            case 9:
                orderStatus.setText("已退货");
                break;
            case 10:
                orderStatus.setText("已完成");
                break;
            case 11:
                orderStatus.setText("待提货");
                break;
            default:
                orderStatus.setText("已完成");
        }
       /* switch (order.getStatus()) {
            case 0:
                orderStatus.setText("待付款");
                btnLayout.setVisibility(View.VISIBLE);
                orderBtn1.setVisibility(View.VISIBLE);
                orderBtn2.setVisibility(View.VISIBLE);
                orderBtn3.setVisibility(View.GONE);
                orderBtn1.setText("立即支付");
                orderBtn2.setText("取消订单");
                break;
            case 1:
                orderStatus.setText("待发货");
                btnLayout.setVisibility(View.VISIBLE);
                orderBtn1.setVisibility(View.VISIBLE);
                orderBtn2.setVisibility(View.GONE);
                orderBtn3.setVisibility(View.GONE);
                orderBtn1.setText("申请退款");
                break;
            case 2:
                orderStatus.setText("待收货");
                btnLayout.setVisibility(View.VISIBLE);
                orderBtn1.setVisibility(View.VISIBLE);
                orderBtn2.setVisibility(View.VISIBLE);
                orderBtn3.setVisibility(View.VISIBLE);
                orderBtn1.setText("确认收货");
                orderBtn2.setText("查看物流");
                orderBtn3.setText("申请退货");
                break;
            case 3:
                orderStatus.setText("待评价");
                btnLayout.setVisibility(View.VISIBLE);
                orderBtn1.setVisibility(View.VISIBLE);
                orderBtn2.setVisibility(View.GONE);
                orderBtn3.setVisibility(View.GONE);
                orderBtn1.setText("评价");
                break;
            case 4:
                orderStatus.setText("交易关闭");
                btnLayout.setVisibility(View.GONE);
                break;
            case 5:
                orderStatus.setText("退款中");
                btnLayout.setVisibility(View.VISIBLE);
                orderBtn1.setVisibility(View.VISIBLE);
                orderBtn2.setVisibility(View.GONE);
                orderBtn3.setVisibility(View.GONE);
                orderBtn1.setText("退款详情");
                break;
            case 6:
                orderStatus.setText("已取消");
                btnLayout.setVisibility(View.VISIBLE);
                orderBtn1.setVisibility(View.VISIBLE);
                orderBtn2.setVisibility(View.GONE);
                orderBtn3.setVisibility(View.GONE);
                orderBtn1.setText("删除订单");
                break;
            case 7:
                orderStatus.setText("已退款");
                btnLayout.setVisibility(View.GONE);
                break;
            case 8:
                orderStatus.setText("退货中");
                btnLayout.setVisibility(View.VISIBLE);
                orderBtn1.setVisibility(View.VISIBLE);
                orderBtn2.setVisibility(View.GONE);
                orderBtn3.setVisibility(View.GONE);
                orderBtn1.setText("退货详情");
                break;
            case 9:
                orderStatus.setText("已退货");
                btnLayout.setVisibility(View.GONE);
                break;
            case 10:
                orderStatus.setText("已评价");
                btnLayout.setVisibility(View.GONE);
            case 11:
                orderStatus.setText("待自提");
                btnLayout.setVisibility(View.VISIBLE);
                orderBtn1.setVisibility(View.VISIBLE);
                orderBtn2.setVisibility(View.VISIBLE);
                orderBtn3.setVisibility(View.VISIBLE);
                orderBtn1.setText("确认收货");
                orderBtn2.setText("申请退货");
                orderBtn3.setText("查看物流");
                break;
            default:
                orderStatus.setText("已完成");
                btnLayout.setVisibility(View.GONE);
        }*/
        userName.setText(String.format("%1$s  %2$s", order.getName(), order.getMobile()));
        userAddr.setText(order.getAddress().getAddress());
        //remark.setVisibility(TextUtils.isEmpty(order.getMemo()) ? View.GONE : View.VISIBLE);
        remark.setText(SpannalbeStringUtils.setTextColor("留言：", ContextCompat.getColor(mContext, R.color._333)));
        remark.append(SpannalbeStringUtils.setTextColor(order.getMemo(), ContextCompat.getColor(mContext, R.color._666)));
        sendMethod.setText(order.getSendMethod()==1?"品行专送":order.getSendMethod()==2?"自提":"快递");

        if (order.getItems() != null) {
            OrderProductAdapter adapter = new OrderProductAdapter(mContext, order.getItems());
            listView.setAdapter(adapter);
            adapter.notifyDataSetChanged();
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    intent = new Intent(mContext, ProductDetailActivity.class);
                    intent.putExtra("productId", order.getItems().get(position).getProductId());
                    startActivity(intent);
                }
            });
        }
        expressMoney.setText(String.format("¥%s", order.getExpressFee().setScale(2, RoundingMode.HALF_UP)));
        couponMoney.setText(String.format("¥%s", order.getCoupon().setScale(2, RoundingMode.HALF_UP)));
        totalMoney.setText(String.format("¥%s", order.getTotalFee().setScale(2, RoundingMode.HALF_UP)));
        orderNo.setText(order.getOrderNo());
        orderCreateTime.setText(order.getCreateTime());
        orderPayTime.setText(order.getPayTime());

        switch (order.getSendMethod()) {
            case 1:
                //品行专送
                viewStub.setLayoutResource(R.layout.layout_service_place);
                viewStub.inflate();
                TextView title = (TextView) findViewById(R.id.title);
                title.setText("配送点信息");
                if (order.getService() == null) {
                    return;
                }
                TextView userName1 = (TextView) findViewById(R.id.user_name1);
                userName1.setText(order.getService().getName() + "  " + order.getService().getMobile());
                TextView userAddr1 = (TextView) findViewById(R.id.user_addr1);
                userAddr1.setText(order.getService().getAddress());
                TextView menu1 = (TextView) findViewById(R.id.addr_extra_menu11);
                TextView menu2 = (TextView) findViewById(R.id.addr_extra_menu22);
                menu1.setOnClickListener(onClickListener);
                menu2.setOnClickListener(onClickListener);
                addrExtraLayout.setVisibility(View.GONE);

                break;
            case 2:
                //自提
                txtReviceveAddr.setText("自提点地址");
                userName.setText(order.getService().getName() + "  " + order.getService().getMobile());
                userAddr.setText(order.getService().getAddress());
                addrExtraLayout.setVisibility(View.VISIBLE);
                break;
            case 3:
                //快递
                txtReviceveAddr.setText("收货地址");
                userName.setText(order.getAddress().getName() + "  " + order.getAddress().getMobile());
                userAddr.setText(order.getAddress().getAddress());
                addrExtraLayout.setVisibility(View.GONE);
                if (order.getStatus() == 2) {
                    viewStub.setLayoutResource(R.layout.layout_service_place);
                    viewStub.inflate();
                    TextView name = (TextView) findViewById(R.id.title);
                    name.setText(order.getExpress());
                    TextView number = (TextView) findViewById(R.id.title);
                    number.setText(order.getExpressNo());
                }
                break;
        }

    }

    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.addr_extra_menu11:
                    //拨打电话  自提
                    showCallRemindDiaLog();
                    break;
                case R.id.addr_extra_menu22:
                    //导航
                    guideRoad();
                    break;
            }
        }
    };

    private void showCallRemindDiaLog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setTitle("温馨提示");
        builder.setMessage("确认拨打电话吗");
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                checkCallPermission();

            }
        });
        builder.show();
    }

    private void guideRoad() {
        String desLatit = order.getService().getLat();
        String desLongit = order.getService().getLng();
        String oriLatit = BaseApplication.getInstance().getLati();
        String oriLongit = BaseApplication.getInstance().getLongti();
        if (isAvilible(mContext, "com.baidu.BaiduMap")) {//传入指定应用包名
            Intent intent = new Intent();
            String uri = String.format("baidumap://map/direction?origin=%1$s,%2$s&destination=%3$s,%4$s&mode=driving", oriLatit, oriLongit, desLatit, desLongit);
            intent.setData(Uri.parse(uri));
            mContext.startActivity(intent); //启动调用

        } else {//未安装
            //market为路径，id为包名
            //显示手机上所有的market商店
            Toast.makeText(mContext, "您尚未安装百度地图", Toast.LENGTH_LONG).show();
            Uri uri = Uri.parse("market://details?id=com.baidu.BaiduMap");
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            mContext.startActivity(intent);
        }
//        if (isAvilible(mContext, "com.autonavi.minimap")) {
//            Intent intent = new Intent();
//            String uri = String.format("androidamap://route?sourceApplication=品行惠&slat=%1$s&slon=%2$s&dlat=%3$s&dlon=%4$s&dev=0&m=0&t=1", oriLatit, oriLongit, desLatit, desLongit);
//            intent.setData(Uri.parse(uri));
//            mContext.startActivity(intent); //启动调用
//        } else {
//            Toast.makeText(mContext, "您尚未安装高德地图", Toast.LENGTH_LONG).show();
//            Uri uri = Uri.parse("market://details?id=com.autonavi.minimap");
//            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
//            mContext.startActivity(intent);
//        }
    }

    @OnClick({R.id.order_btn1, R.id.order_btn2, R.id.addr_extra_menu1, R.id.addr_extra_menu2})
    void onClick(View v) {
        switch (v.getId()) {
            case R.id.order_btn1:
                switch (order.getStatus()) {
                    case 4:
                    case 6://删除订单
                        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                        builder.setTitle("温馨提示");
                        builder.setMessage("确认删除订单吗？");
                        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
                        builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                delOrder();

                            }
                        });
                        builder.show();
                        break;
                    case 0://支付订单
                        intent = new Intent(mContext, OrderPayActivity.class);
                        intent.putExtra("orderId", order.getOrderId());
                        intent.putExtra("totalMoney", String.format("%s", order.getTotalFee().setScale(2, RoundingMode.HALF_UP)));
                        startActivity(intent);
                        break;
                    case 1://申请退款
                        intent = new Intent(mContext, ApplyRefundActivity.class);
                        intent.putExtra("order", order);
                        intent.putExtra("type", 1);//申请退款
                        startActivity(intent);
                        break;
                    case 2://确认收货
                    case 11:
                        confirmRecieve();
                        break;
                    case 3:
                        //评价
                        intent = new Intent(mContext, MakeCommentActivity.class);
                        intent.putExtra("order", order);
                        startActivity(intent);
                        break;
                    case 5:
                        //查看退款详情
                        intent = new Intent(mContext, RefundDetailActivity.class);
                        intent.putExtra("order", order);
                        startActivity(intent);
                        break;
                    case 8:
                        //查看退货详情
                        intent = new Intent(mContext, RefundDetailActivity.class);
                        intent.putExtra("order", order);
                        startActivity(intent);
                        break;
                }
                break;
            case R.id.order_btn2:
                switch (order.getStatus()) {
                    case 0://取消订单
                        cancelOrder();
                        break;
                    case 2://查看物流
                        if (order.getSendMethod() != 3) {
                            //品行专送  自提
                            //申请退货
                            intent = new Intent(mContext, PinxingLogisticsActivity.class);
                            intent.putExtra("order", order);
                            //intent.putExtra("type", 2);//申请退货
                            startActivity(intent);
                        } else {
                            intent = new Intent(mContext, WebViewActivity.class);
                            String url = String.format("https://m.kuaidi100.com/index_all.html?type=%1$s&postid=%2$s", order.getExpressCode(), order.getExpressNo());
                            intent.putExtra("url", url);
                            intent.putExtra("title", "物流查询");
                            startActivity(intent);
                        }

                        break;
                    case 11:
                        //申请退货
                        intent = new Intent(mContext, ApplyRefundActivity.class);
                        intent.putExtra("order", order);
                        intent.putExtra("type", 2);//申请退货
                        startActivity(intent);
                        break;
                }
                break;
            case R.id.order_btn3:
                if (order.getStatus() == 2) {
                    //申请退货
                    intent = new Intent(mContext, ApplyRefundActivity.class);
                    intent.putExtra("order", order);
                    intent.putExtra("type", 2);//申请退货
                    startActivity(intent);
                } else if (order.getStatus() == 11) {
                    intent = new Intent(mContext, PinxingLogisticsActivity.class);
                    intent.putExtra("order", order);
                    startActivity(intent);
                }
                break;
            case R.id.addr_extra_menu1:
                //拨打电话 自提
                showCallRemindDiaLog();
                break;
            case R.id.addr_extra_menu2:
                //导航  自提
                guideRoad();
                break;

        }
    }

    private static final int MY_PERMISSIONS_REQUEST_CALL_PHONE = 1;

    private void checkCallPermission() {
        if (ContextCompat.checkSelfPermission(mContext,
                Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            // 没有获得授权，申请授权
            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.CALL_PHONE)) {
                // 返回值：
//                          如果app之前请求过该权限,被用户拒绝, 这个方法就会返回true.
//                          如果用户之前拒绝权限的时候勾选了对话框中”Don’t ask again”的选项,那么这个方法会返回false.
//                          如果设备策略禁止应用拥有这条权限, 这个方法也返回false.
                // 弹窗需要解释为何需要该权限，再次请求授权
                Toast.makeText(this, "请授权！", Toast.LENGTH_LONG).show();

                // 帮跳转到该应用的设置界面，让用户手动授权
                Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                Uri uri = Uri.fromParts("package", getPackageName(), null);
                intent.setData(uri);
                startActivity(intent);
            } else {
                // 不需要解释为何需要该权限，直接请求授权
                ActivityCompat.requestPermissions(this,
                        new String[]{Manifest.permission.CALL_PHONE},
                        MY_PERMISSIONS_REQUEST_CALL_PHONE);
            }
        } else {
            // 已经获得授权，可以打电话
            CallPhone();
        }
    }

    // 处理权限申请的回调
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case MY_PERMISSIONS_REQUEST_CALL_PHONE: {
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // 授权成功，继续打电话
                    CallPhone();
                } else {
                    // 授权失败！
                    Toast.makeText(this, "授权失败！", Toast.LENGTH_LONG).show();
                }
                break;
            }
        }

    }

    private void CallPhone() {
        String number = order.getService().getMobile();
        if (TextUtils.isEmpty(number)) {
            // 提醒用户
            // 注意：在这个匿名内部类中如果用this则表示是View.OnClickListener类的对象，
            // 所以必须用MainActivity.this来指定上下文环境。
            ToastUtils.showToast(mContext, "号码不能为空");
        } else {
            // 拨号：激活系统的拨号组件
            Intent intent = new Intent(); // 意图对象：动作 + 数据
            intent.setAction(Intent.ACTION_CALL); // 设置动作
            Uri data = Uri.parse("tel:" + number); // 设置数据
            intent.setData(data);
            startActivity(intent); // 激活Activity组件
        }

    }

    /**
     * 检查手机上是否安装了指定的软件
     *
     * @param context
     * @param packageName：应用包名
     * @return
     */
    public static boolean isAvilible(Context context, String packageName) {
        //获取packagemanager
        final PackageManager packageManager = context.getPackageManager();
        //获取所有已安装程序的包信息
        List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
        //用于存储所有已安装程序的包名
        List<String> packageNames = new ArrayList<String>();
        //从pinfo中将包名字逐一取出，压入pName list中
        if (packageInfos != null) {
            for (int i = 0; i < packageInfos.size(); i++) {
                String packName = packageInfos.get(i).packageName;
                packageNames.add(packName);
            }
        }
        //判断packageNames中是否有目标程序的包名，有TRUE，没有FALSE
        return packageNames.contains(packageName);
    }

    private void delOrder() {
        showLoadingDialog(0);
        Call<ResultDO> call = ApiClient.getApiAdapter().delOrder(order.getOrderId(), memberId);
        call.enqueue(new Callback<ResultDO>() {
            @Override
            public void onResponse(Call<ResultDO> call, Response<ResultDO> response) {
                if (isFinish) {
                    return;
                }
                dissMissDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getCode() == 0) {
                    finish();
                } else {
                    ToastUtils.showToast(mContext, response.body().getMessage());
                }
            }

            @Override
            public void onFailure(Call<ResultDO> call, Throwable t) {
                dissMissDialog();
                ToastUtils.showToast(mContext, R.string.network_error);
            }
        });
    }


    private void confirmRecieve() {
        showLoadingDialog(0);
        Call<ResultDO> call = ApiClient.getApiAdapter().confirmRecieve(order.getOrderId(), memberId);
        call.enqueue(new Callback<ResultDO>() {
            @Override
            public void onResponse(Call<ResultDO> call, Response<ResultDO> response) {
                if (isFinish) {
                    return;
                }
                dissMissDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getCode() == 0) {
                    finish();
                } else {
                    ToastUtils.showToast(mContext, response.body().getMessage());
                }
            }

            @Override
            public void onFailure(Call<ResultDO> call, Throwable t) {
                dissMissDialog();
                ToastUtils.showToast(mContext, R.string.network_error);
            }
        });
    }

    private void cancelOrder() {
        showLoadingDialog(0);
        Call<ResultDO> call = ApiClient.getApiAdapter().cancelOrder(order.getOrderId(), memberId);
        call.enqueue(new Callback<ResultDO>() {
            @Override
            public void onResponse(Call<ResultDO> call, Response<ResultDO> response) {
                if (isFinish) {
                    return;
                }
                dissMissDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getCode() == 0) {
                    finish();
                } else {
                    ToastUtils.showToast(mContext, response.body().getMessage());
                }
            }

            @Override
            public void onFailure(Call<ResultDO> call, Throwable t) {
                dissMissDialog();
                ToastUtils.showToast(mContext, R.string.network_error);
            }
        });
    }

}
